package org.mantis.ta;

import java.math.BigInteger;
import java.rmi.RemoteException;
import java.util.List;

import javax.xml.rpc.ServiceException;

import org.mantis.ta.beans.AccountData;
import org.mantis.ta.beans.IssueData;
import org.mantis.ta.beans.IssueHeaderData;
import org.mantis.ta.beans.ProjectData;

public class Simple {
	public static void main(String[] args) throws RequiredItemException, ServiceException, RemoteException {
		MantisManager manager = new MantisManager("http://localhost:8008/",
				"administrator", "root");

		try {
			System.out.println(manager.getVersion());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// manager.setItemsPerPage(1);
		try {
			List<ProjectData> projects = manager.getProjects();
			for (ProjectData project : projects) {
				System.out.println(project.getName() + " : "
						+ project.getDescription());

				List<IssueData> headers = manager.getIssuesByProject(project
						.getId());
				for (IssueData header : headers) {
					System.out.println(header.getId() + ": "
							+ header.getSummary());
				}
			}
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		List<AccountData> users;
		try {
			users = manager.getUsers();

			for (AccountData user : users) {
				System.out.println(user.getName());
			}
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

        BigInteger prjId = new BigInteger("63");
        try {
				List<IssueData> headers = manager.getIssuesByProject(prjId);
				for (IssueData header : headers) {
					System.out.println("delete issue: " + header.getId());
                    manager.deleteIssue(header.getId());
				}
            manager.deleteProject(prjId);
            System.out.println("project: " + prjId + " deleted successfully");
        } catch (Exception e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }

}
